package InnerClassDemo;


class OuterClass2 {
    public int data1=1;
    private int data2=2;
    public static int data3=3;

    /**
     * 静态内部类
     *生成静态内部类对象时不需要外部类对象的引用
     *
     */
    static class InnerClass {
        public int data4=4;
        private int data5=5;
        public static final int data6=6;

        public void test() {
            System.out.println("static InnerClass test");
//            System.out.println(data1);//静态内部类不能访问外部类成员，那如何访问？
//            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
        }
    }

    public void testA() {
        System.out.println("OuterClass2 testA");
    }
}
public class Test2 {

    public static void main(String[] args) {
        OuterClass2 out2=new OuterClass2();
        out2.testA();
        System.out.println(out2.data1);

        new OuterClass2().testA();
        System.out.println(new OuterClass2().data1);
    }


    public static void main1(String[] args) {
        /*
        如何生成静态内部类的对象？
         */
        OuterClass2.InnerClass innerClass=new OuterClass2.InnerClass();
        innerClass.test();

        OuterClass2 out=new OuterClass2();
        System.out.println(out.data1);
//        System.out.println(out.data2);//data2是private
        System.out.println(out.data3);

    }
}
